import os
from pathlib import Path
import yaml

BASE_DIR = Path(__file__).parent.parent

def load_config():
    config_path = BASE_DIR / 'config.yaml'
    with open(config_path, 'r', encoding='utf-8') as f:
        return yaml.safe_load(f)

class Config:
    def __init__(self):
        config = load_config()
        
        # 数据库配置
        self.SQLALCHEMY_DATABASE_URI = config['database']['uri']
        self.SQLALCHEMY_TRACK_MODIFICATIONS = False
        self.SQLALCHEMY_ENGINE_OPTIONS = {
            'pool_size': 20,
            'max_overflow': 10,
            'pool_recycle': 3600,
            'pool_pre_ping': True
        }
        
        # Redis配置
        self.REDIS_HOST = config['redis']['host']
        self.REDIS_PORT = config['redis']['port']
        self.REDIS_DB = config['redis']['db']
        
        # JWT配置
        self.JWT_SECRET_KEY = config['jwt']['secret_key']
        self.JWT_ACCESS_TOKEN_EXPIRES = config['jwt']['access_token_expires']
        
        # WebSocket配置
        self.WS_HEARTBEAT_INTERVAL = config['websocket']['heartbeat_interval']
        self.WS_MESSAGE_QUEUE_SIZE = config['websocket']['message_queue_size']
        
        # 性能配置
        self.MESSAGE_PROCESSING_WORKERS = config['performance']['message_processing_workers']
        
        # 日志配置
        self.LOG_LEVEL = config['logging']['level']
        self.LOG_FILE = config['logging']['file']

config = Config()